home *** CD-ROM | disk | FTP | other *** search
/ QuickTime 2.0 Developer Kit / QuickTime 2.0 Developer Kit.iso / mac / MAC / Programming Stuff / Interfaces / CIncludes / fenv.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-11  |  12.4 KB  |  277 lines  |  [TEXT/MPS ]

  1. /*******************************************************************************
  2. *                                                                              *
  3. *      File fenv.h - PowerPC 601 version,                                      *
  4. *                                                                              *
  5. *      A collection of functions designed to provide access to the floating    *
  6. *      point environment for numerical programming. It is modeled after the    *
  7. *      Numerical C Extensions Group’s requirements ( NCEG / X3J11.1 ).         *
  8. *                                                                              *
  9. *      The file <fenv.h> declares many functions in support of numerical       *
  10. *      programming.  It provides a set of environmental controls similar to    *
  11. *      the ones found in <SANE.h>.  Programs that test flags or run under      *
  12. *      non-default modes must do so under the effect of an enabling            *
  13. *      "fenv_access" pragma.                                                   *
  14. *                                                                              *
  15. *      Copyright © 1992-1994 Apple Computer, Inc.  All rights reserved.        *
  16. *                                                                              *
  17. *      Written by Ali Sazegari, started on October 1992.                       *
  18. *                                                                              *
  19. *      CHANGE LOG (most recent changes first)                                  *
  20. *                                                                              *
  21. *      13 May 94      PAF      Added fegetprec and fesetprec and               *
  22. *                              corresponding macros for 68K                    *
  23. *      22 Feb 94      PAF      Modified for 68K compatability                  *
  24. *      23 Aug 93      ali      included C++ extern "C" wrappers to make        *
  25. *                              them C++ friendly.                              *
  26. *      08 Apr 93      ali      changed "enums" to "macros" to be more          *
  27. *                              compatible with the FPCE of NCEG.               *
  28. *      05 Feb 93      JPO      Changed function types of feclearexcept,        *
  29. *                              fegetexcept, feraiseexcept, and fesetexcept     *
  30. *                              from int to void to reflect changes in NCEG     *
  31. *                              specification.  Changed definition of           *
  32. *                              FE_DFL_ENV from typedef to #define.  Modified   *
  33. *                              comments describing functionality.              *
  34. *                                                                              *
  35. *******************************************************************************/
  36.  
  37. #ifndef __FENV__
  38. #define __FENV__
  39.  
  40.  
  41. #ifdef      powerc
  42.  
  43. /*    The typedef fenv_t is a type for representing the entire floating-point
  44.       environment in a single object.                                         */
  45.  
  46. typedef      long int      fenv_t;
  47.  
  48. /*    The typedef fexcept_t is a type for representing the floating-point
  49.       exception flag state collectively.                                      */
  50.  
  51. typedef      long int      fexcept_t;
  52.  
  53. /*    Definitions of floating-point exception macros                          */
  54.  
  55. #define      FE_INEXACT         0x02000000
  56. #define      FE_DIVBYZERO       0x04000000
  57. #define      FE_UNDERFLOW       0x08000000
  58. #define      FE_OVERFLOW        0x10000000
  59. #define      FE_INVALID         0x20000000
  60.  
  61. /*    Definitions of rounding direction macros                                */
  62.  
  63. #define      FE_TONEAREST       0x00000000 
  64. #define      FE_TOWARDZERO      0x00000001 
  65. #define      FE_UPWARD          0x00000002 
  66. #define      FE_DOWNWARD        0x00000003
  67.  
  68. #else        /* powerc    */
  69.  
  70. #ifdef    mc68881
  71.  
  72. typedef  long fexcept_t;
  73. typedef struct {
  74.     long FPCR;
  75.     long FPSR;
  76. } fenv_t;
  77.  
  78. #define      FE_INEXACT        ((long)(8))
  79. #define      FE_DIVBYZERO      ((long)(16))
  80. #define      FE_UNDERFLOW      ((long)(32))
  81. #define      FE_OVERFLOW       ((long)(64))
  82. #define      FE_INVALID        ((long)(128))
  83.  
  84. #else     /* mc68881    */
  85.  
  86. typedef  short fexcept_t;
  87. typedef  short fenv_t;
  88.  
  89. #define      FE_INVALID        ((short)(1))
  90. #define      FE_UNDERFLOW      ((short)(2))
  91. #define      FE_OVERFLOW       ((short)(4))
  92. #define      FE_DIVBYZERO      ((short)(8))
  93. #define      FE_INEXACT        ((short)(16))
  94.  
  95. #endif    /* mc68881    */
  96.  
  97. #define FE_TONEAREST           ((short)(0))
  98. #define FE_UPWARD              ((short)(1))
  99. #define FE_DOWNWARD            ((short)(2))
  100. #define FE_TOWARDZERO          ((short)(3))
  101.  
  102. /*    Definitions of rounding precision macros  (68K only)                    */
  103.  
  104. #define FE_LDBLPREC            ((short)(0))
  105. #define FE_DBLPREC             ((short)(1))
  106. #define FE_FLTPREC             ((short)(2))
  107.  
  108. #endif    /* powerc    */
  109.  
  110. /*    The bitwise OR of all exception macros                                  */
  111.  
  112. #define      FE_ALL_EXCEPT     ( FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID )
  113.  
  114. /*    Definition of pointer to IEEE default environment object                */
  115.  
  116. extern fenv_t _FE_DFL_ENV;               /* default environment object        */
  117. #define FE_DFL_ENV &_FE_DFL_ENV          /* pointer to default environment    */
  118.  
  119.  
  120. #ifdef __cplusplus
  121. extern "C" {
  122. #endif
  123.  
  124. /*******************************************************************************
  125. *     The following functions provide access to the exception flags.  The      *
  126. *     "int" input argument can be constructed by bitwise ORs of the exception  *
  127. *     macros: for example: FE_OVERFLOW | FE_INEXACT.                           *
  128. *******************************************************************************/
  129.  
  130. /*******************************************************************************
  131. *     The function "feclearexcept" clears the supported exceptions represented *
  132. *     by its argument.                                                         *
  133. *******************************************************************************/
  134.  
  135. void feclearexcept ( int excepts );
  136.  
  137.  
  138.  
  139. /*******************************************************************************
  140. *    The function "fegetexcept" stores a representation of the exception       *
  141. *     flags indicated by the argument "excepts" through the pointer argument   *
  142. *     "flagp".                                                                 *
  143. *******************************************************************************/
  144.  
  145. void fegetexcept ( fexcept_t *flagp, int excepts );
  146.  
  147.  
  148.  
  149. /*******************************************************************************
  150. *     The function "feraiseexcept" raises the supported exceptions             *
  151. *     represented by its argument.                                             *
  152. *******************************************************************************/
  153.  
  154. void feraiseexcept ( int excepts );
  155.  
  156.  
  157.  
  158. /*******************************************************************************
  159. *     The function "fesetexcept" sets or clears the exception flags indicated  *
  160. *     by the int argument "excepts" according to the representation in the     *
  161. *     object pointed to by the pointer argument "flagp".  The value of         *
  162. *     "*flagp" must have been set by a previous call to "fegetexcept".         *
  163. *     This function does not raise exceptions; it just sets the state of       *
  164. *     the flags.                                                               *
  165. *******************************************************************************/
  166.  
  167. void fesetexcept ( const fexcept_t *flagp, int excepts );
  168.  
  169.  
  170.  
  171. /*******************************************************************************
  172. *     The function "fetestexcept" determines which of the specified subset of  *
  173. *     the exception flags are currently set.  The argument "excepts" specifies *
  174. *     the exception flags to be queried as a bitwise OR of the exception       *
  175. *     macros.  This function returns the bitwise OR of the exception macros    *
  176. *     corresponding to the currently set exceptions included in "excepts".     *
  177. *******************************************************************************/
  178.  
  179. int fetestexcept ( int excepts );
  180.  
  181.  
  182.  
  183. /*******************************************************************************
  184. *     The following functions provide control of rounding direction modes.     *
  185. *******************************************************************************/
  186.  
  187. /*******************************************************************************
  188. *     The function "fegetround" returns the value of the rounding direction    *
  189. *     macro which represents the current rounding direction.                   *
  190. *******************************************************************************/
  191.  
  192. int fegetround ( void );
  193.  
  194.  
  195.  
  196. /*******************************************************************************
  197. *     The function "fesetround" establishes the rounding direction represented *
  198. *     by its argument.  It returns nonzero if and only if the argument matches *
  199. *     a rounding direction macro.  If not, the rounding direction is not       *
  200. *     changed.                                                                 *
  201. *******************************************************************************/
  202.  
  203. int fesetround ( int round );
  204.  
  205.  
  206.  
  207. /*******************************************************************************
  208. *    The following functions manage the floating-point environment, exception  *
  209. *    flags and dynamic modes, as one entity.                                   *
  210. *******************************************************************************/
  211.  
  212. /*******************************************************************************
  213. *     The function "fegetenv" stores the current floating-point environment    *
  214. *     in the object pointed to by its pointer argument "envp".                 *
  215. *******************************************************************************/
  216.  
  217. void fegetenv ( fenv_t *envp );
  218.  
  219.  
  220.  
  221. /*******************************************************************************
  222. *     The function "feholdexcept" saves the current environment in the object  *
  223. *     pointed to by its pointer argument "envp", clears the exception flags,   *
  224. *     and clears floating-point exception enables.  This function supersedes   *
  225. *     the SANE function "procentry", but it does not change the current        *
  226. *     rounding direction mode.                                                 *
  227. *******************************************************************************/
  228.  
  229. int feholdexcept ( fenv_t *envp );
  230.  
  231.  
  232.  
  233. /*******************************************************************************
  234. *     The function "fesetenv" installs the floating-point environment          *
  235. *     environment represented by the object pointed to by its argument         *
  236. *     "envp".  The value of "*envp" must be set by a call to "fegetenv" or     *
  237. *     "feholdexcept", by an implementation-defined macro of type "fenv_t",     *
  238. *     or by the use of the pointer macro FE_DFL_ENV as the argument.           *
  239. *******************************************************************************/
  240.  
  241. void fesetenv ( const fenv_t *envp );
  242.  
  243.  
  244.  
  245. /*******************************************************************************
  246. *     The function "feupdateenv" saves the current exceptions into its         *
  247. *     automatic storage, installs the environment represented through its      *
  248. *     pointer argument "envp", and then re-raises the saved exceptions.        *
  249. *     This function, which supersedes the SANE function "procexit", can be     *
  250. *     used in conjunction with "feholdexcept" to write routines which hide     *
  251. *     spurious exceptions from their callers.                                  *
  252. *******************************************************************************/
  253.       
  254. void feupdateenv ( const fenv_t * envp );
  255.  
  256. #ifndef powerc
  257.  
  258. /*******************************************************************************
  259. *     The following functions provide control of rounding precision.           *
  260. *     Because the PowerPC does not provide this capability, these functions    *  
  261. *     are available only for the 68K Macintosh.  Rounding precision values     *
  262. *     are defined by the rounding precision macros.  These functions are       *
  263. *     equivalent to the SANE functions getprecision and setprecision.          *
  264. *******************************************************************************/
  265.  
  266. int fegetprec ( void );
  267. int fesetprec ( int precision );
  268.  
  269. #endif
  270.  
  271. #ifdef __cplusplus
  272. }
  273. #endif
  274.  
  275.  
  276. #endif    /*  __FENV__ */
  277.